package com.jxnd.sunflower.service.Impl;

import com.jxnd.sunflower.domain.RGoods;
import com.jxnd.sunflower.domain.dto.NavGoodsDTO;
import com.jxnd.sunflower.mapper.RGoodsMapper;
import com.jxnd.sunflower.service.GoodsService;
import com.jxnd.sunflower.utils.RedisOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 敷衍
 * @description:
 * @date: 2021/11/26 13:14
 * @version: 1.0
 */
@Service
public class GoodsServiceImpl implements GoodsService {


    @Autowired
    private RGoodsMapper goodsMapper;

    @Autowired
    private RedisOperator redis;

    @Value("${server.port}")
    private String port;

    @Override
    public List<NavGoodsDTO> selectNav(Integer status) {
        List<NavGoodsDTO> navGoodDTOS = goodsMapper.selectNav(status);
        for (NavGoodsDTO goods: navGoodDTOS) {
            String subImages = ("http://127.0.0.1:"+port +"/"+goods.getSubImages());
            goods.setSubImages(subImages);
        }
        return navGoodDTOS;
    }

    @Override
    public RGoods queryInfo(Integer status) {
        //redis 浏览量
        redis.increment(status.toString(),1);
        RGoods rGoods = goodsMapper.queryInfo(status);
        String subImages = ("http://127.0.0.1:"+port +"/"+rGoods.getSubImages());
        rGoods.setSubImages(subImages);
        return rGoods;
    }
}
